<?php
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('home', 'register');
$this->breadcrumbs = array(
    Yii::t('home', 'register')
);
?>

<h1><?= Yii::t('register', 'register') ?></h1>

<!--<p>Please fill out the following form with your login credentials:</p>-->

<div class="form">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'register-form',
        'enableClientValidation' => true,
        'clientOptions' => array(
            'validateOnSubmit' => true,
        ),
        'focus' => array($model, 'username'),
    ));
    ?>

    <p class="note"><?= Yii::t('register', 'require_star') ?></p>

    <div class="row">
        <?php echo $form->labelEx($model, 'username'); ?>
        <?php echo $form->textField($model, 'username'); ?>
        <?php echo $form->error($model, 'username'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'password'); ?>
        <?php echo $form->passwordField($model, 'password'); ?>
        <?php echo $form->error($model, 'password'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'repassword'); ?>
        <?php echo $form->passwordField($model, 'repassword'); ?>
        <?php echo $form->error($model, 'repassword'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'firstname'); ?>
        <?php echo $form->textField($model, 'firstname'); ?>
        <?php echo $form->error($model, 'firstname'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'lastname'); ?>
        <?php echo $form->textField($model, 'lastname'); ?>
        <?php echo $form->error($model, 'lastname'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'gender'); ?>
        <?php echo $form->dropDownList($model, 'gender', array('M' => Yii::t('register','male'), 'F' => Yii::t('register','female'))); ?>
        <?php echo $form->error($model, 'gender'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'birthday'); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model' => $model,
            'name' => 'birthday',
            'options' => array(
                'showButtonPanel' => true,
                'ttonImageOnly' => false,
                'showAnim'=>'slide',
                'dateFormat' => 'dd-mm-yy',
                'dayNamesMin' => array('อา','จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'),
                'monthNamesShort' => array('มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม',
                    'มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'),
                'changeMonth' => true,
                'changeYear' => true,
                'yearRange'=>'1900:2099',
                'beforeShow' => 'js:function(){  
                    if($(this).val() != ""){
                        var arrayDate = $(this).val().split("-");  
                        if (parseInt(arrayDate[2]) > 2400) {
                            arrayDate[2] = parseInt(arrayDate[2]) - 543;
                        }
                        $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);
                    }
                    setTimeout(function(){
                        $.each($(".ui-datepicker-year option"), function(j, k){
                            var textYear = "";
                            if(parseInt($(".ui-datepicker-year option").eq(j).val()) < 2400){
                                textYear = parseInt($(".ui-datepicker-year option").eq(j).val()) + 543;
                            }
                            $(".ui-datepicker-year option").eq(j).text(textYear);
                        });             
                    },50);
                }',
                'onClose' => 'js:function(){
                    if($(this).val() != "" && $(this).val() == dateBefore){         
                        var arrayDate = dateBefore.split("-");
                        if (parseInt(arrayDate[2]) < 2400) {
                            arrayDate[2] = parseInt(arrayDate[2]) + 543;
                        }
                        $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);    
                    }       
                }',
                'onSelect' => 'js:function(dateText, inst){ 
                    dateBefore = $(this).val();
                    var arrayDate = dateText.split("-");
                    if (parseInt(arrayDate[2]) < 2400) {
                        arrayDate[2] = parseInt(arrayDate[2]) + 543;
                    }
                    $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);
                }', 
            ),
            'htmlOptions' => array(
                'style' => 'height:20px;'
            ),
        ));
        ?>
        <?php echo $form->error($model, 'birthday'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'time_of_birthday'); ?>
        <?php
        $this->widget('application.extensions.timepicker.EJuiDateTimePicker', array(
            'model' => $model,
            'name' => 'time_of_birthday',
            'value' => '00:00',
            'options' => array(
                'showOn' => 'focus',
                'timeFormat' => 'hh:mm',
                'timeOnly' => true,
            ),
            'htmlOptions' => array(
                'style' => 'width:150px;', // styles to be applied
                'maxlength' => '10', // textField maxlength
            ),
        ));
        ?>
        <?php echo $form->error($model, 'time_of_birthday'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'mobilephone'); ?>
        <?php echo $form->textField($model, 'mobilephone'); ?>
        <?php echo $form->error($model, 'mobilephone'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'profile_image'); ?>
        <?php echo $form->fileField($model, 'profile_image'); ?>
        <?php echo $form->error($model, 'profile_image'); ?>
    </div>

    <div class="row rememberMe">
        <?php // echo $form->checkBox($model, 'rememberMe');  ?>
        <?php // echo $form->label($model, 'rememberMe');  ?>
        <?php // echo $form->error($model, 'rememberMe');  ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton(Yii::t('register', 'register')); ?>
    </div>

    <?php $this->endWidget(); ?>
</div><!-- form -->
